﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Runtime.InteropServices;
using TableTop.DataManagement.Addon;
using System.Windows.Media.Imaging;
using System.Windows.Markup;
using System.Windows;

using TableTop.DataManagement;
using TableTop.Presentation.Controls;

namespace TableTop
{
    [Serializable]
    public class GenericRPGEntryPoint
        : IAddonEntryPoint
    {
        public GenericRPGEntryPoint()
            : base()
        {
        }

        public Guid GUID
        {
            get
            {
                //GuidAttribute gaAttribute = null;
                //Assembly aCurrentAssembly = null;
                //Guid gdCurrentGuid = Guid.Empty;

                //aCurrentAssembly = Assembly.GetExecutingAssembly();
                //gaAttribute = (GuidAttribute)aCurrentAssembly.GetCustomAttributes(typeof(GuidAttribute), false)[0];
                //gdCurrentGuid = new Guid(gaAttribute.Value);
                return AddonHelper.GUID;
            }
        }

        public string Name
        {
            get
            {
                //AssemblyTitleAttribute ataAttribute = null;
                //Assembly aCurrentAssembly = null;
                //String strCurrentTitle = String.Empty;

                //aCurrentAssembly = Assembly.GetExecutingAssembly();
                //ataAttribute = (AssemblyTitleAttribute)aCurrentAssembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false)[0];
                //strCurrentTitle = ataAttribute.Title;
                //return strCurrentTitle;
                return AddonHelper.Name;
            }
        }

        public ResourceDictionary Resources
        {
            get
            {
                return AddonHelper.Resources;
            }
            // private set;
        }

        public string Description
        {
            get
            {
                //AssemblyDescriptionAttribute ataAttribute = null;
                //Assembly aCurrentAssembly = null;
                //String strCurrentTitle = String.Empty;

                //aCurrentAssembly = Assembly.GetExecutingAssembly();
                //ataAttribute = (AssemblyDescriptionAttribute)aCurrentAssembly.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false)[0];
                //strCurrentTitle = ataAttribute.Description;
                //return strCurrentTitle;
                return AddonHelper.Description;
            }
        }

        //protected void LocateResources()
        //{
        //    this.Resources = new Presentation.Themes.Generic();
        //}

        public Type GetAddonType(TableTopControls RequestedType)
        {
            ////Assembly aCurrentAssembly = null;
            //Type tRequestedType = null;

            ////aCurrentAssembly = Assembly.GetCallingAssembly();

            //switch (RequestedType)
            //{
            //    case TableTopControls.Unknown:
            //        throw new ArgumentException("Cannot get Unknown type");

            //    case TableTopControls.CharacterSheetEditor:
            //        tRequestedType = typeof(GenericRPGEntryPoint);
            //        break;
            //    default:
            //        throw new ArgumentException("Argument out of range");
            //}

            //return tRequestedType;
            return AddonHelper.GetAddonType(RequestedType);
        }

        public object CreateAddonTypeInstance(TableTopControls RequestedType)
        {
            //Object objResult = null;

            //switch (RequestedType)
            //{
            //    case TableTopControls.Unknown:
            //        throw new ArgumentException("Cannot instantiate an Unknown type");

            //    case TableTopControls.CharacterSheetEditor:
            //        objResult = new GRPGCharacterSheetEditor();
            //        break;

            //    default:
            //        throw new ArgumentException("Argument out of range");
            //}

            //return objResult;
            return AddonHelper.CreateAddonTypeInstance(RequestedType);
        }

        public String AddonIcon
        {
            get
            {
                //Assembly aCurrentAssembly = null;
                //String strPackString = String.Empty;
                //String strAssemblyName = String.Empty;

                //aCurrentAssembly = Assembly.GetExecutingAssembly();
                //strAssemblyName = aCurrentAssembly.GetName().Name;
                //strPackString = String.Format("pack://application:,,,/{0};component/Images/rpg_dock_icon.png",
                //                              strAssemblyName);
                //return strPackString;
                return AddonHelper.AddonIcon;
            }
        }
    }
}
